package test6;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-07
 * Time: 19:58
 */

//使用静态内部类创建单例模式
public class SingletonTest06 {
    public static void main(String[] args) {
        Singleton singleton = Singleton.getInstance();
        Singleton instance = Singleton.getInstance();
        System.out.println(singleton == instance);
    }
}

class Singleton{
    private static volatile Singleton instance;

    //写一个静态内部类 该类当中有一个静态属性
    private static class SingletonInstance{
        private static final Singleton INSTANCE = new Singleton();
    }

    //提供一个静态的共有方法
    public static Singleton getInstance(){
        return SingletonInstance.INSTANCE;
    }

}
